package org.sixtythousand.joker.netty;

import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.*;
import org.sixtythousand.joker.Server;
import org.sixtythousand.joker.handler.Handler;
import org.sixtythousand.joker.handler.LinkedHandler;
import org.sixtythousand.joker.http.*;
import org.sixtythousand.joker.http.AbstractHttpRequest;
import org.sixtythousand.joker.http.HttpRequest;
import org.sixtythousand.joker.http.HttpResponse;
import org.sixtythousand.joker.servlet.ServletHandler;
import org.sixtythousand.joker.servlet.session.SessionHandler;

/**
 * @author zhoulk
 * @date 2023/10/11 13:40
 * @desc
 */
public class NettyServer extends Server {

    public static void main(String[] args) {
        Server server = new NettyServer();
//        HttpHandlerManager handlerManager = new HttpHandlerManager(new HttpHandlerWrapper("/hello",
//                new HttpHandler() {
//                    @Override
//                    public void doHandler(HttpRequest request, HttpResponse rsp) {
//                        NettyHttpChannel channel = (NettyHttpChannel) request.getChannel();
//                        String content = "Hello, World!";
//                        FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
//                                Unpooled.wrappedBuffer(content.getBytes()));
//                        response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");
//                        response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
//                        channel.getCtx().writeAndFlush(response);
//                    }
//                }));
        LinkedHandler handler = new SessionHandler();
        handler.addHandlers(new ServletHandler());
        NettyServerConnector connector = new NettyServerConnector(8899, server, null, handler, new NettyConnectionFactory());
        server.handlerManager(new HttpHandlerManager());
        server.connector(connector);
        server.start();
    }

    public NettyServer() {
    }


}
